package com.yycx.base.provider.handler;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.UpdateInterceptor;
import com.yycx.common.mybatis.query.CriteriaUpdate;
import com.yycx.common.utils.event.FlymeEventClient;
import com.yycx.module.admin.client.entity.BaseUser;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 后台用户添加扩展
 *
 * @author zyf
 */
@Component
public class BaseUserUpdateForMinioEditHandler implements UpdateInterceptor<BaseUser> {

    @Resource
    private FlymeEventClient flymeEventClient;

    @Override
    public void complete(CriteriaUpdate cu, EntityMap params, BaseUser baseUser) {
        if (FlymeUtils.isNotEmpty(baseUser)) {
            EntityMap map = new EntityMap();
            map.put("userName", FlymeUtils.isNotEmpty(baseUser.getAccount()) ? baseUser.getAccount() : baseUser.getUserName());
            map.put("password", baseUser.getPassword());
            map.put("optType", "delete");
            flymeEventClient.publishEvent("minioAddUserListener", map);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            map.put("optType", "add");
            flymeEventClient.publishEvent("minioAddUserListener", map);
        }
    }
}
